package com.icedbrew.appfuel.util;

/**
 * Created by IntelliJ IDEA.
 * User: Omar
 * Date: 5/20/12
 * Time: 2:51 PM
 * To change this template use File | Settings | File Templates.
 */
public class StringUtil {
    /* Empty String Constant */
    public static final String EMPTY_STRING = "";

    public static boolean isEmpty(final String string) {
        return string == null || EMPTY_STRING.equals(string);
    }

    public static boolean isEmptyOrWhiteSpace(final String string) {
        return isEmpty(string) || string.trim().length() == 0;
    }

    public static boolean isAlpha(final String string) {
        if (isEmptyOrWhiteSpace(string))
            return false;
        for (char character : string.toCharArray()) {
            if (!Character.isLetter(character)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isAlphaNumeric(final String string) {
        if (isEmptyOrWhiteSpace(string))
            return false;
        for (char character : string.toCharArray()) {
            boolean isNotCharacter = !Character.isLetter(character);
            boolean isNotDigit = !Character.isDigit(character);
            if (isNotCharacter || isNotDigit) {
                return false;
            }
        }
        return true;
    }
}
